package com.hxzy.service.impl;

import com.hxzy.entity.TbUserFromId;
import com.hxzy.mapper.TbUserFromIdMapper;
import com.hxzy.service.TbUserFromIdService;
import com.hxzy.util.MybatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class TbUserFromIdServiceImpl implements TbUserFromIdService {
    @Override
    public TbUserFromId selectByPrimaryKey(Long id) {
        TbUserFromId tbUserFromId=null;
        try (SqlSession session= MybatisUtil.getSqlSessionFactory().openSession()){
            TbUserFromIdMapper mapper = session.getMapper(TbUserFromIdMapper.class);
            tbUserFromId=mapper.selectByPrimaryKey(id);
        }
        return tbUserFromId;
    }

    @Override
    public boolean insert(TbUserFromId record) {
        int count=0;
        try (SqlSession session=MybatisUtil.getSqlSessionFactory().openSession()){
            TbUserFromIdMapper mapper = session.getMapper(TbUserFromIdMapper.class);
            count=mapper.insert(record);
            session.commit();
        }
        return count>0;
    }

    @Override
    public boolean updateByPrimaryKey(TbUserFromId record) {
        int count=0;
        try (SqlSession session=MybatisUtil.getSqlSessionFactory().openSession()){
            TbUserFromIdMapper mapper = session.getMapper(TbUserFromIdMapper.class);
            count=mapper.updateByPrimaryKey(record);
            session.commit();
        }
        return count>0;
    }

    @Override
    public boolean updateByPrimaryKeySelective(TbUserFromId record) {
        int count=0;
        try (SqlSession session=MybatisUtil.getSqlSessionFactory().openSession()){
            TbUserFromIdMapper mapper = session.getMapper(TbUserFromIdMapper.class);
            count=mapper.updateByPrimaryKeySelective(record);
            session.commit();
        }
        return count>0;
    }

    @Override
    public List<TbUserFromId> search() {
        List<TbUserFromId> search=null;
        try (SqlSession session=MybatisUtil.getSqlSessionFactory().openSession()){
            TbUserFromIdMapper mapper = session.getMapper(TbUserFromIdMapper.class);
             search= mapper.search();

        }
        return search;
    }

    @Override
    public List<TbUserFromId> searchByCondition(TbUserFromId tbUserFromId) {
        List<TbUserFromId> list;
        try (SqlSession session=MybatisUtil.getSqlSessionFactory().openSession()){
            TbUserFromIdMapper mapper = session.getMapper(TbUserFromIdMapper.class);
            list = mapper.searchByCondition(tbUserFromId);
        }
        return list;
    }
}
